
const { addUVLOG, queryUVLOG, queryUVLOGByDay
    //  getUVLOGDetail, deltetUVLOG
} = require("../../../controller/webSite/vistorlogs/vistorlogs-controller");
const { serverError } = require("../../../utils");
const { emptyCheck } = require("../../../utils/checkEmpty");

/**
 * @description 访客统计路由
 * @author 韩
 */
const router = require("koa-router")()
router.prefix("/website/vistorlogs");

// 添加或编辑
router.post("/add", async (ctx, next) => {
    try {

        const { pageTitle, ip, path } = ctx.request.body
        const check = emptyCheck({ ip })
        if (check.code !== 0) {
            ctx.body = check
        } else {
            const res = await addUVLOG({
                pageTitle, ip, path

            })
            ctx.body = res
        }
    } catch (error) {
        console.log(error)
        ctx.body = serverError
    }
})

// // 查询列表
router.post("/list", async (ctx, next) => {
    try {
        const { pageUrl = null, ip = null, endDateTime = null, startDateTime = null, pageSize = 10, current = 1, } = ctx.request.body;
        const res = await queryUVLOG({
            pageUrl, ip, endDateTime, startDateTime, pageSize, current
        })
        ctx.body = res
    } catch (error) {
        console.log(error)
        ctx.body = serverError
    }

})


//查询指定时间段内的访客数量，并按天分组
router.post("/listByDay", async (ctx, next) => {
    try {
        const { pageUrl = null, ip = null, endDateTime = null, startDateTime = null, pageSize = 10, current = 1, dateType = "today" } = ctx.request.body;
        const res = await queryUVLOGByDay({
            pageUrl, ip, endDateTime, startDateTime, pageSize, current, dateType
        })
        ctx.body = res
    } catch (error) {
        console.log(error)
        ctx.body = serverError
    }
})




// // 删除
// router.post("/delete", async (ctx, next) => {
//     try {
//         const { id } = ctx.request.body
//         const check = emptyCheck({ id })
//         if (check.code!== 0) {
//             ctx.body = check;
//         }
//         else {
//             const res = await deltetArticle({ _id: id })
//             ctx.body = res;
//         }
//     } catch (error) {
//         ctx.body = serverError
//     }
// })

// // 查看专题详情
// router.post("/detail", async (ctx, next) => {
//     try {
//         const { _id } = ctx.request.body
//         const check = emptyCheck({ _id })
//         if (check.code!== 0) {
//             ctx.body = check;
//         } else {
//             const res = await getSubjectDetail({ _id: _id })
//             ctx.body = res;
//         }

//     } catch (error) {
//         ctx.body = serverError
//     }
// })

module.exports = router